//
//  JUser.swift
//  JMicroBlog
//
//  Created by Jason on 21/5/15.
//  Copyright (c) 2015 Shepherd. All rights reserved.
//

import UIKit

class JUser: NSObject {
   
    // id
    var id : Int = 0
    
    // 友好显示名称,别名
    var name : String?
    
    // 头像 50 * 50
    var profile_image_url : String? {
        didSet {
            iconURL = NSURL(string: profile_image_url!)
        }
    }
    
    // 用户头像的URL
    var iconURL : NSURL?
    
    // 认证类型  -1:没有认证 0:认证用户 2,3,5 企业认证 220:草根明星
    var verify_type : Int = -1
    
    // 会员等级 1~6
    var mbrank : Int = 0
    
    // 会员认证
    var vipImage : UIImage? {
        switch verify_type {
        case 0: return UIImage(named: "avatar_vip")
        case 2,3,5:return UIImage(named: "avatar_enterprise_vip")
        case 220:return UIImage(named: "avatar_grassroot")
        default:return nil
        }
    }
    
    var memberImage:UIImage? {
        if mbrank > 0 && mbrank < 7 {
            return UIImage(named: "common_icon_membership_level\(mbrank)")
        }
        return nil
    }
    
    private static let properties = ["id","name","profile_image_url","verify_type","mbrank"]
    
    // 使用KVC为User信息初始化
    init(dict : [String:AnyObject]) {
        super.init()
        for key in JUser.properties {
            if dict[key] != nil {
                setValue(dict[key], forKey: key)
            }
        }
    }
}
